/*
 * fcompare.c
 * Asif Shahidullah
 *
 * An implementation of a floating point comparison. This function
 * is a little different than the traditional relative error
 * method. 
 *
 * We multiply the operands by a large value and truncate the remaining
 * decimal points. Then we simply perform an integer comparison. It
 * is possible to use this method because we know the data range 
 * and how precise we need to be; i.e, this wouldn't work in a
 * general case.
 */

#include <stdio.h>
#include "fcompare.h"

int fcompare (float op1, float op2) {
	const float multiplier = 100000.0f;
	int i_op1, i_op2;

	/* Multiply to get the precision digits, and truncate
	 * the remaining decimal points. */	
	i_op1 = (int) (op1 * multiplier);
	i_op2 = (int) (op2 * multiplier);

	if (i_op1 == i_op2)
		return 0;
	else if (i_op1 < i_op2)
		return -1;
	else
		return 1;
}
